package com.esisa.swing;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class ButtonPanel extends JPanel {
	
	public ButtonPanel(String labels[]) {
		for (int i = 0; i < labels.length; i++) {
			JButton b = new JButton(labels[i]);
			add(b);
		}
	}

	public ButtonPanel(String labels[], int width) {
		for (int i = 0; i < labels.length; i++) {
			JButton b = new JButton(labels[i]);
			b.setToolTipText(labels[i]);
			b.setPreferredSize(new Dimension(width, 25));
			add(b);
		}
	}
	
	public void addActionListner(ActionListener action, String nameButton){
		for (int i = 0; i < this.getComponentCount(); i++) {
			JButton b =  (JButton) getComponent(i);
			if(b.getText().equalsIgnoreCase(nameButton)){
				b.addActionListener(action);
				return;
			}
		}		
	}
	
	public void addActionListner(ActionListener action, int index){
		JButton b =  (JButton) getComponent(index);
		b.addActionListener(action);
	}
	
	public void addActionListner(ActionListener action){
		for (int i = 0; i < this.getComponentCount(); i++) {
			this.addActionListner(action, i);
		}		
	}
	
	public void AddMouseListner(MouseListener action, String nameButton){
		for (int i = 0; i < this.getComponentCount(); i++) {
			JButton b =  (JButton) getComponent(i);
			if(b.getText().equalsIgnoreCase(nameButton)){
				b.addMouseListener(action);
				return;
			}
		}		
	}
	
	public void AddMouseListner(MouseListener action, int index){
		JButton b =  (JButton) getComponent(index);
		b.addMouseListener(action);
	}
	
	public void AddMouseListner(MouseListener action){
		for (int i = 0; i < this.getComponentCount(); i++) {
			AddMouseListner(action, i);
		}
	}
}
